<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<%@ include file="../common.jsp"%>
	<title>管理员列表_test</title>
</head>
<body style="width: 960px; height: 540px;">
<div class="easyui-layout" style="width: 98%; height: 98%;margin:auto;">
	<div id="div_search" data-options="region:'north',title:'检索条件'" style="height: 150px">
		<form id="form_search">
			<input type="hidden" name="id" value="1">
			<ul>
				<li><label for="name">名称:</label><input id="name_search" name="name" type="text"/></li>
			</ul>		
		</form>
	</div>
	
	<!-- 数据展示开始 -->	
	<div id="div_datagrid" data-options="region:'center',title:'数据表格'">
		<!--操作按钮开始-->
		<div id="toolbar"> 
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="showAddDialog();">新增</a> 
			&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="showModifyDialog();">修改</a> 
			&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="enable()">启用</a>
			&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="disable()">停用</a>			
		</div>
		<!--操作按钮结束--> 
		<table id="tbl_datagrid"></table>
	</div>
	<!-- 数据展示结束 -->
</div>
	<script type="text/javascript">
	var columns_test = [];
	column_test_row1 = [];
	column_test_row1.push({title:"",colspan:3});
	column_test_row2 = [  
	{title : 'ID', field : 'id', sortable:true, width : 80,halign:'center',align : 'left',
	  formatter: function(value,row,index){				  
			return value;
		}
	},
	{title : '姓名', field : 'name', sortable:true, width : 180,halign:'center',align : 'left',
	  formatter: function(value,row,index){				  
			return value;
		}
	},
	{title : '状态', field : 'storeStatus', sortable:true, width : 80,halign:'center',align : 'left',
		  formatter: function(value,row,index){				  
				return ({"true":"生效","false":"失效"}[value]) || "";
			}
	}];
	$(function(){
		var x_url = basePath + '/admin/getRoles';  
		var param = {};
		$.ajax({
			url: x_url,
			type: 'POST',
			dataType: 'json',
			data: param,
			async : false
		})
		.done(function(result) {
			if (result && result.flag && result.data) {
				column_test_row1.push({title:"角色",colspan:result.data.length});
				$.each(result.data, function(i,data){
					column_test_row2.push({title : data.name, field : data.id+"."+data.name, sortable:true, width : 180,halign:'center',align : 'left',
						  formatter: function(value,row,index){
							  var formatter_result = "-";
							  $.each(row.roles,function(i,role){
								  console.info("role.id :"+role.id);
								  console.info("data.id :"+data.id);
								  if(role.id == data.id){
									  formatter_result = "+";
									  return ; 
								  }
							  });
							  return formatter_result;
							}
					});
				});
				columns_test.push(column_test_row1);
				columns_test.push(column_test_row2);
			};
		})
		.fail(function() {
			$.messager.alert('温馨提示','网络异常','error');
		});
		
		init_datagrid();
		$('#tbl_datagrid').datagrid({columns:columns_test});
		search();
		
		
	
	});	
	var init_datagrid = function(){
		$('#tbl_datagrid').datagrid({
			url : '',
			title:'',
			method: 'post',
			loadMsg: "数据装载中....",
			nowrap: false,
			striped: true,
			pagination: true,
			fitColumns:false,
			rownumbers : true,
			checkbox : false,
			singleSelect : true,
			remoteSort : false,
			toolbar : '#toolbar',
			pageSize : 20,
			height:$('#div_datagrid').height()-50,
			pageList : [20, 50, 100 ],
			//columns : columns_test
		});
	};
	var search = function(){
		var x_url = basePath + '/admin/getData_datagrid_test';
		console.info(x_url);
		var param = {};
		$.each($('#form_search').serializeArray(), function(i,data){
			param[data['name']] = data['value'];
		});
		$('#tbl_datagrid').datagrid('options').url = x_url;
		$('#tbl_datagrid').datagrid('load',param);
	};
	</script>
</body>
</html>